package com.bw.finance.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bw.finance.conf.ResponseResult;
import com.bw.finance.eneity.locana.EbankRes;
import com.bw.finance.service.IEbankResService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zxx
 * @since 2020-08-19
 */
@RestController
@RequestMapping("/ebankres")
public class EbankResController {
    @Autowired
    private IEbankResService resService;

    @PostMapping("/addpic")
    public ResponseResult addpic(@RequestBody EbankRes ebankRes){
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            resService.saveOrUpdate(ebankRes);
            result.setMessage("保存成功");
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("添加失败");
        }
        return result;
    }

    @GetMapping("/delpic/{path}")
    public ResponseResult delpic(@PathVariable String path){
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            QueryWrapper<EbankRes> queryWrapper=new QueryWrapper();
            queryWrapper.lambda().eq(EbankRes::getExt,path);
            EbankRes ebankRes = resService.getOne(queryWrapper);
            resService.removeById(ebankRes.getId());
            result.setMessage("删除成功");
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("删除失败");
        }
        return result;
    }
}
